module ChessTips {

    export function find(myChess: Array<Poker_DDZ>, UpChess: Array<Poker_DDZ>) {
        //下面注释测试用
        /** 
         *  // Poker_DDZ.init();
        // let list = [
        //     1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
        //     17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
        //     33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
        //     49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
        //     78, 79]
        // let list = [
        //     1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
        //     17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
        //     // 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
        //     // 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
        //     78, 79]
        // let list2 = [11, 12, 13, 27, 28, 29];
        // DdzVO.getVo().chessListUp = Poker_DDZ.idChangeObject(list2);
        // DdzVO.getVo().chessListUp = Poker_DDZ.sort(DdzVO.getVo().chessListUp);
        // DdzVO.getVo().chessListMy = Poker_DDZ.idChangeObject(list);
        // DdzVO.getVo().chessListMy = Poker_DDZ.sort(DdzVO.getVo().chessListMy);
        // ChessTips.find(DdzVO.getVo().chessListMy, DdzVO.getVo().chessListUp);
        // let upType = ChessType.getType(DdzVO.getVo().chessListUp);
        // DdzProxy.getProxy()
         * 
         */


        let upType = DdzVO.getVo().upPlayType;//上次出的牌型
        let chessGroup = chessSplice(myChess);  //我的手牌拆分后的牌组
        let canPlayGroup: Array<Array<Poker_DDZ>> = [];  //我可以出的牌组
        //1先判断对方是火箭我无法出任何牌
        DdzVO.getVo().canPlayType = 0;
        if (upType == ChessType.cboom) {
            return canPlayGroup;
        }
        //2再判断前面两家过牌我可以随便出
        if (UpChess.length == 0) {
            DdzVO.getVo().canPlayType = 1;
            return canPlayGroup;
        }
        //3然后按照对方的牌型依次查找我可以应付的牌
        if (upType == ChessType.c1)
            canPlayGroup = isDan(UpChess, chessGroup, canPlayGroup)
        else if (upType == ChessType.c2)
            canPlayGroup = isDuiZi(UpChess, chessGroup, canPlayGroup)
        else if (upType == ChessType.c3)
            canPlayGroup = isSanBuDai(UpChess, chessGroup, canPlayGroup)
        else if (upType == ChessType.c4)
            canPlayGroup = isZhaDan(UpChess, chessGroup, canPlayGroup)
        else if (upType == ChessType.c31)
            canPlayGroup = isSanDaiYi(UpChess, chessGroup, canPlayGroup)
        else if (upType == ChessType.c123)
            canPlayGroup = isShunZi(UpChess, chessGroup, canPlayGroup)
        else if (upType == ChessType.c1122)
            canPlayGroup = isLianDui(UpChess, chessGroup, canPlayGroup)
        else if (upType == ChessType.c32)
            canPlayGroup = isSanDaiEr(UpChess, chessGroup, canPlayGroup)
        else if (upType == ChessType.c111222)
            canPlayGroup = isDuoFeiJiBuDai(UpChess, chessGroup, canPlayGroup)
        else if (upType == ChessType.c11122234)
            canPlayGroup = isDuoFeiJiDaiDan(UpChess, chessGroup, canPlayGroup)
        else if (upType == ChessType.c1112223344)
            canPlayGroup = isDuoFeiJiDaiShuang(UpChess, chessGroup, canPlayGroup)
        else if (upType == ChessType.c411)
            canPlayGroup = isSiDaiEr(UpChess, chessGroup, canPlayGroup)
        else if (upType == ChessType.c422)
            canPlayGroup = isSiDaiErDui(UpChess, chessGroup, canPlayGroup)
        //4最后看我是否有炸弹（对方不炸的情况下，对方若出炸，3已处理）和火箭
        if (upType != ChessType.c4) {
            for (let k = 3; k < chessGroup.length; k++) {
                for (let i = 0; i < chessGroup[k].length; i++) {
                    if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                        canPlayGroup[canPlayGroup.length] = [];
                    }
                    canPlayGroup[canPlayGroup.length - 1] = chessGroup[k][i];
                }
            }
        }
        //火箭必可出
        let xiaowang = null;
        let dawang = null;
        for (let i = 0; i < chessGroup[0].length; i++) {
            if (chessGroup[0][i][0].value == 14) {
                xiaowang = chessGroup[0][i][0]
            }
            if (chessGroup[0][i][0].value == 15) {
                dawang = chessGroup[0][i][0]
            }
        }
        if (xiaowang != null && dawang != null) {
            let wang = [xiaowang, dawang]
            if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                canPlayGroup[canPlayGroup.length] = [];
            }
            canPlayGroup[canPlayGroup.length - 1] = wang;
        }
        return canPlayGroup;
    }
    export function isDan(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        //找出上家牌最大值
        let upNum = UpChess[0].value;
        //先取单牌//再拆对子,再拆飞机，只取其中一个牌就行
        for (let k = 0; k < chessGroup.length - 1; k++) {//length-1不拆炸弹
            for (let i = 0; i < chessGroup[k].length; i++) {
                if (chessGroup[k][i][0].value > upNum) {
                    if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                        canPlayGroup[canPlayGroup.length] = [];
                    }
                    canPlayGroup[canPlayGroup.length - 1].push(chessGroup[k][i][0]);//单对子飞机都只取一个用push(0)
                }
            }
        }
        return canPlayGroup;
    }

    export function isDuiZi(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        let upNum = UpChess[0].value;
        //先取对子,再拆飞机
        for (let k = 1; k < chessGroup.length - 1; k++) {//length-1不拆炸弹
            for (let i = 0; i < chessGroup[k].length; i++) {
                if (chessGroup[k][i][0].value > upNum) {
                    if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                        canPlayGroup[canPlayGroup.length] = [];
                    }
                    canPlayGroup[canPlayGroup.length - 1] = chessGroup[k][i].slice(0, 2);//飞机和对子都取2个用slice
                }
            }
        }
        return canPlayGroup;
    }

    export function isSanBuDai(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        let upNum = UpChess[0].value;
        //取飞机
        for (let k = 2; k < chessGroup.length - 1; k++) {//length-1不拆炸弹
            for (let i = 0; i < chessGroup[k].length; i++) {
                if (chessGroup[k][i][0].value > upNum) {
                    if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                        canPlayGroup[canPlayGroup.length] = [];
                    }
                    canPlayGroup[canPlayGroup.length - 1] = chessGroup[k][i];//必定取三个直接=
                }
            }
        }
        return canPlayGroup;
    }

    export function isZhaDan(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        let upNum = UpChess[0].value;
        for (let k = 3; k < chessGroup.length; k++) {
            for (let i = 0; i < chessGroup[k].length; i++) {
                if (chessGroup[k][i][0].value > upNum) {
                    if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                        canPlayGroup[canPlayGroup.length] = [];
                    }
                    canPlayGroup[canPlayGroup.length - 1] = chessGroup[k][i];//必定取4个直接=
                }
            }
        }
        return canPlayGroup;
    }

    export function isSanDaiYi(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        let list = chessSplice(UpChess);
        let upNum = list[2][0][0].value;
        for (let k = 2; k < chessGroup.length - 1; k++) {
            for (let i = 0; i < chessGroup[k].length; i++) {
                if (chessGroup[k][i][0].value > upNum) {
                    let list1 = chessGroup[k][i];//记录下主牌再找副牌，副牌中排除主牌
                    let list2 = JSON.parse(JSON.stringify(chessGroup));
                    list2[k].splice(i, 1)
                    let n = findDan(list2, 1)//找副牌

                    if (n.length != 0) {//找到了副牌才能保留这一组
                        if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                            canPlayGroup[canPlayGroup.length] = [];
                        }
                        canPlayGroup[canPlayGroup.length - 1] = chessGroup[k][i];
                        canPlayGroup[canPlayGroup.length - 1] = canPlayGroup[canPlayGroup.length - 1].concat(n);
                    }
                }
            }
        }
        return canPlayGroup;
    }

    //顺子和连对的处理方式比较特殊，需要把飞机和炸弹拆分成对子或单
    export function isShunZi(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        let list = [];
        let myChess = DdzVO.getVo().chessListMy;
        for (let i = 0; i < myChess.length; i++) {
            if (Global.isEmpty(list[myChess[i].value])) {
                list[myChess[i].value] = [];
            }
            list[myChess[i].value].push(myChess[i]);
        }
        //按出现次数装入数组，此处不论对子还是飞机还是炸弹都装入单牌一张
        let list2: Array<Array<Poker_DDZ>> = [[], [], [], []]
        for (let i in list) {
            if (Global.isEmpty(list[i])) {
                continue;
            }
            list2[0].push(list[i][0]);
        }
        //剔除王 2 
        let chessGroup3: Array<Poker_DDZ> = []
        for (let i = 0; i < list2[0].length; i++) {
            if (list2[0][i].value != 13 && list2[0][i].value != 14 && list2[0][i].value != 15) {
                chessGroup3.push(list2[0][i]);
            }
        }

        let upNum = UpChess[0].value;
        let upLeng = UpChess.length
        for (let i = 0; i < chessGroup3.length; i++) {
            if (chessGroup3.length - i < upLeng) {
                return canPlayGroup;
            }
            if (chessGroup3[i + upLeng - 1].value > upNum) {
                let list3 = chessGroup3.slice(i, i + upLeng)
                if ((list3[list3.length - 1].value - list3[0].value) == list3.length - 1) {
                    if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                        canPlayGroup[canPlayGroup.length] = [];
                    }
                    canPlayGroup[canPlayGroup.length - 1] = list3;
                }
            }
        }
        return canPlayGroup;
    }

    export function isLianDui(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        let myChess = DdzVO.getVo().chessListMy;
        let upNum = UpChess[0].value;
        let upLeng = UpChess.length
        //先看每张牌出现次数
        let list: Array<Array<Poker_DDZ>> = [];
        for (let i = 0; i < myChess.length; i++) {
            if (Global.isEmpty(list[myChess[i].value])) {
                list[myChess[i].value] = [];
            }
            list[myChess[i].value].push(myChess[i]);
        }
        //按出现次数装入数组，飞机和炸弹都转入对子2张
        let list2: Array<Poker_DDZ> = []
        for (let i in list) {
            if (Global.isEmpty(list[i])) {
                continue;
            }
            if (list[i].length >= 2) {
                list2 = list2.concat(list[i].slice(0, 2));
            }
        }
        //剔除 2 
        let chessGroup3: Array<Poker_DDZ> = []
        for (let i = 0; i < list2.length; i++) {
            if (list2[i].value != 13) {
                chessGroup3.push(list2[i]);
            }
        }
        list2 = chessGroup3;
        for (let i = 0; i < list2.length; i += 2) {
            if (list2.length - i < upLeng) {
                return canPlayGroup;
            }
            if (list2[i + upLeng - 1].value > upNum) {
                let list3 = list2.slice(i, i + upLeng)
                if ((list3[list3.length - 1].value - list3[0].value) == list3.length / 2 - 1) {
                    if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                        canPlayGroup[canPlayGroup.length] = [];
                    }
                    canPlayGroup[canPlayGroup.length - 1] = canPlayGroup[canPlayGroup.length - 1].concat(list3);
                }
            }
        }

        return canPlayGroup;
    }

    export function isSanDaiEr(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        let list = chessSplice(UpChess);
        let upNum = list[2][0][0].value;

        for (let k = 2; k < chessGroup.length - 1; k++) {
            for (let i = 0; i < chessGroup[k].length; i++) {
                if (chessGroup[k][i][0].value > upNum) {
                    let list1 = chessGroup[k][i];//记录下主牌再找副牌，副牌中排除主牌
                    let list2 = JSON.parse(JSON.stringify(chessGroup));
                    list2[k].splice(i, 1)
                    let n = findShuang(list2, 1)//找副牌

                    if (n.length != 0) {//找到了副牌才能保留这一组
                        if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                            canPlayGroup[canPlayGroup.length] = [];
                        }
                        canPlayGroup[canPlayGroup.length - 1] = chessGroup[k][i];
                        canPlayGroup[canPlayGroup.length - 1] = canPlayGroup[canPlayGroup.length - 1].concat(n);
                    }
                }
            }
        }
        return canPlayGroup;
    }

    export function isSiDaiEr(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        let list = chessSplice(UpChess);
        let upNum = list[3][0][0].value;

        for (let k = 3; k < chessGroup.length; k++) {
            for (let i = 0; i < chessGroup[k].length; i++) {
                if (chessGroup[k][i][0].value > upNum) {
                    let list1 = chessGroup[k][i];//记录下主牌再找副牌，副牌中排除主牌
                    let list2 = JSON.parse(JSON.stringify(chessGroup));
                    list2[k].splice(i, 1)
                    let n = findDan(list2, 2)//找副牌

                    if (n.length != 0) {//找到了副牌才能保留这一组
                        if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                            canPlayGroup[canPlayGroup.length] = [];
                        }
                        canPlayGroup[canPlayGroup.length - 1] = chessGroup[k][i];
                        canPlayGroup[canPlayGroup.length - 1] = canPlayGroup[canPlayGroup.length - 1].concat(n);
                    }
                }
            }
        }
        return canPlayGroup;
        // //四带二直接炸他丫的啊
        // return canPlayGroup;
    }

    export function isSiDaiErDui(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        let list = chessSplice(UpChess);
        let upNum = list[3][0][0].value;

        for (let k = 3; k < chessGroup.length; k++) {
            for (let i = 0; i < chessGroup[k].length; i++) {
                if (chessGroup[k][i][0].value > upNum) {
                    let list1 = chessGroup[k][i];//记录下主牌再找副牌，副牌中排除主牌
                    let list2 = JSON.parse(JSON.stringify(chessGroup));
                    list2[k].splice(i, 1)
                    let n = findShuang(list2, 2)//找副牌

                    if (n.length != 0) {//找到了副牌才能保留这一组
                        if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                            canPlayGroup[canPlayGroup.length] = [];
                        }
                        canPlayGroup[canPlayGroup.length - 1] = chessGroup[k][i];
                        canPlayGroup[canPlayGroup.length - 1] = canPlayGroup[canPlayGroup.length - 1].concat(n);
                    }
                }
            }
        }
        // return canPlayGroup;
        //四带二对也直接炸他丫的啊
        return canPlayGroup;
    }

    export function isDuoFeiJiBuDai(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        let list = chessSplice(UpChess);
        let upLeng = list[2].length;
        let upNum = list[2][list[2].length - 1][0].value;
        if (chessGroup[2].length < upLeng) {//飞机没有上家多直接pass
            return canPlayGroup;
        }

        for (let k = 2; k < chessGroup.length - 1; k++) {
            for (let i = 0; i < chessGroup[k].length; i++) {
                if ((chessGroup[k].length - i < upLeng)) {//遍历过程中剩余的飞机数量没对方多
                    return canPlayGroup;
                }
                if (chessGroup[k][i][0].value > upNum) {
                    let list2 = chessGroup[k].slice(i, i + upLeng)
                    if ((list2[list2.length - 1][0].value - list2[0][0].value) == (list2.length - 1)) {
                        if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                            canPlayGroup[canPlayGroup.length] = [];
                        }
                        for (let i in list2) {
                            canPlayGroup[canPlayGroup.length - 1] = canPlayGroup[canPlayGroup.length - 1].concat(list2[i]);
                        }
                    }
                }
            }
        }
        return canPlayGroup;
    }

    export function isDuoFeiJiDaiDan(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        let list = chessSplice(UpChess);
        let upLeng = list[2].length;
        let upNum = list[2][list[2].length - 1][0].value;
        if (chessGroup[2].length < upLeng) {//飞机没有上家多直接pass
            return canPlayGroup;
        }

        for (let k = 2; k < chessGroup.length - 1; k++) {
            for (let i = 0; i < chessGroup[k].length; i++) {
                if ((chessGroup[k].length - i < upLeng)) {//遍历过程中剩余的飞机数量没对方多
                    return canPlayGroup;
                }

                if (chessGroup[k][i + upLeng - 1][0].value > upNum) {
                    let list2 = chessGroup[k].slice(i, i + upLeng)

                    let list3 = JSON.parse(JSON.stringify(chessGroup));
                    list3[k].splice(i, upLeng)

                    if ((list2[list2.length - 1][0].value - list2[0][0].value) == (list2.length - 1)) {
                        let n = findDan(list3, upLeng)//找副牌
                        if (n.length != 0) {
                            if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                                canPlayGroup[canPlayGroup.length] = [];
                            }
                            for (let i in list2) {
                                canPlayGroup[canPlayGroup.length - 1] = canPlayGroup[canPlayGroup.length - 1].concat(list2[i]);
                            }
                            canPlayGroup[canPlayGroup.length - 1] = canPlayGroup[canPlayGroup.length - 1].concat(n);
                        }
                    }
                }
            }
        }
        return canPlayGroup;
    }

    export function isDuoFeiJiDaiShuang(UpChess: Array<Poker_DDZ>, chessGroup: Array<Array<Array<Poker_DDZ>>>, canPlayGroup: Array<Array<Poker_DDZ>>) {
        let list = chessSplice(UpChess);
        let upLeng = list[2].length;
        let upNum = list[2][list[2].length - 1][0].value;
        if (chessGroup[2].length < upLeng) {//飞机没有上家多直接pass
            return canPlayGroup;
        }

        for (let k = 2; k < chessGroup.length - 1; k++) {
            for (let i = 0; i < chessGroup[k].length; i++) {
                if ((chessGroup[k].length - i < upLeng)) {//遍历过程中剩余的飞机数量没对方多
                    return canPlayGroup;
                }
                if (chessGroup[k][i + upLeng - 1][0].value > upNum) {
                    let list2 = chessGroup[k].slice(i, i + upLeng)
                    let list3 = JSON.parse(JSON.stringify(chessGroup));
                    list3[k].splice(i, upLeng)
                    if ((list2[list2.length - 1][0].value - list2[0][0].value) == (list2.length - 1)) {
                        let n = findShuang(list3, upLeng)//找副牌
                        if (n.length != 0) {
                            if (Global.isEmpty(canPlayGroup[canPlayGroup.length])) {
                                canPlayGroup[canPlayGroup.length] = [];
                            }
                            for (let i in list2) {
                                canPlayGroup[canPlayGroup.length - 1] = canPlayGroup[canPlayGroup.length - 1].concat(list2[i]);
                            }
                            canPlayGroup[canPlayGroup.length - 1] = canPlayGroup[canPlayGroup.length - 1].concat(n);
                        }
                    }
                }
            }
        }
        return canPlayGroup;
    }

    //把手牌按出现次数拆分并装入一个数组。数组下标对应：0 单 1 对子 2 飞机 3 炸弹
    export function chessSplice(myChess: Array<Poker_DDZ>): Array<Array<Array<Poker_DDZ>>> {
        //先看每张牌出现次数
        let list = [];
        for (let i = 0; i < myChess.length; i++) {
            if (Global.isEmpty(list[myChess[i].value])) {
                list[myChess[i].value] = [];
            }
            list[myChess[i].value].push(myChess[i]);
        }
        //按出现次数装入数组，下标 0 单 2 对 3 飞机 4 炸弹
        let list2: Array<Array<Array<Poker_DDZ>>> = [[], [], [], []]
        for (let i in list) {
            if (Global.isEmpty(list[i])) {
                continue;
            }
            list2[list[i].length - 1].push(list[i]);
        }
        return list2;
    }
    /*
    *再剩余的牌中查找指定的数量的牌
    num 要多少个
    */
    export function findDan(chessGroup: Array<Array<Array<Poker_DDZ>>>, num: number) {
        let leng = num;
        let n: Array<Poker_DDZ> = [];
        let bank: Array<Poker_DDZ> = [];
        for (let k = 0; k < chessGroup.length; k++) {
            for (let i = 0; i < chessGroup[k].length; i++) {
                for (let j = 0; j < chessGroup[k][i].length; j++) {
                    //在拆单牌时如果遇到大小王先记下来而不存入，当遍历完所有牌都没有找到需要的单牌时才考虑拆大小王
                    //只有在0中找单牌才会遇到大小王
                    if (k == 0) {
                        if (chessGroup[k][i][j].value == 14 || chessGroup[k][i][j].value == 15) {
                            bank = [];
                            bank = bank.concat(chessGroup[k][i].slice(j, j + 1));
                        } else {
                            n = n.concat(chessGroup[k][i].slice(j, j + 1));
                        }
                    } else {
                        n = n.concat(chessGroup[k][i].slice(j, j + 1));
                    }
                    if (n.length == leng) {
                        return n;
                    }
                }
            }
        }
        //找单牌时只找到了王而没有发现其他单牌则存入王
        if (n.length == 0 && bank.length != 0) {
            n = n.concat(bank);
        }
        //如果没有找到足够的数量，则之前的也清空
        if (n.length != leng) {
            n = [];
        }
        return n;
    }
    export function findShuang(chessGroup: Array<Array<Array<Poker_DDZ>>>, num: number) {
        let leng = num * 2
        let n: Array<Poker_DDZ> = [];
        let bank: Array<Poker_DDZ> = [];
        for (let k = 1; k < chessGroup.length; k++) {
            for (let i = 0; i < chessGroup[k].length; i++) {
                for (let j = 0; j < chessGroup[k][i].length; j += 2) {//取对子一次取2个跳过2个，取飞机一次取3个跳3个，自己去想
                    if (chessGroup[k][i].length - j < 2)//飞机3个剩一个不够取跳过
                        break;
                    //找2个对子做副牌的时候不允许把炸弹拆分成2个对子，比如AAAA kk kk
                    let val = chessGroup[k][i][j].value;
                    let len = 0;
                    for (let b in n) {
                        if (n[b].value == val) {
                            len++;
                        }
                    }
                    if (len < 2) {
                        n = n.concat(chessGroup[k][i].slice(j, j + 2));
                    }
                    if (n.length == leng) {
                        return n;
                    }
                }
            }
        }
        //如果没有找到足够的数量，则之前的也清空
        if (n.length != leng) {
            n = [];
        }
        return n;
    }
} 